﻿using UnityEngine;
using System.Collections;
using System;
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
using System.Runtime.InteropServices;
#endif

public class BehaviacSystem {

    private static BehaviacSystem _instance = null;
    public static BehaviacSystem instance {
        get {
            if (_instance == null) {
                _instance = new BehaviacSystem();
            }

            return _instance;
        }
    }

    protected static BehaviacFileManager _fileManager = null;
    private string workspaceExportPath {
        get {
            string relativePath = "/behaviac/workspace/exported";
            string path = "";
            if (Application.platform == RuntimePlatform.WindowsEditor) {
                path = Application.dataPath + relativePath;
            } else if (Application.platform == RuntimePlatform.WindowsPlayer) {
                path = Application.dataPath + relativePath;
            } else {
                path = "Assets" + relativePath;
            }

            return path;
        }
    }

    public bool Init() {
        if (_fileManager == null) {
            _fileManager = new BehaviacFileManager();
        }

        {
            //< write log file
            behaviac.Config.IsLogging = true;
            //behaviac.Config.IsSocketing = false;

            behaviac.Workspace.Instance.FilePath = this.workspaceExportPath;
            behaviac.Workspace.Instance.FileFormat = behaviac.Workspace.EFileFormat.EFF_xml;

            //register names
            behaviac.Agent.RegisterInstanceName<GameScene>("gameScene");
            behaviac.Workspace.Instance.ExportMetas("behaviac/workspace/xmlmeta/TanksWar.xml");

            behaviac.Debug.Log("Behaviac meta data export over.");
            behaviac.Agent.SetIdMask(0xffffffff);
        }

        return true;
    }

    public void Uninit() {
        behaviac.Workspace.Instance.Cleanup();
    }

}
